<?php
session_start();
$active = 'flyers';
if(!isset($_SESSION['id']))
{
	header("Location: index.php");
	exit();
}
require("../../db/opendb.php");
$query = "select * from Users where Username='".$_SESSION["username"]."'";
$result = mysql_query($query) or die ("SQL Error".mysql_error());
$row=mysql_fetch_assoc($result);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Realivent -- Listing Designer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../accounts/style.css">
<style type="text/css">
@import "../../accounts/accounts.css";.style1 {
	color: #000000;
	font-weight: bold;
}
.style2 {
	color: #FF0000;
	font-weight: bold;
}
.style3 {color: #666666}
</style>
</head>
<body>
<CENTER>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
<TR><tD><?php include('../../accounts/accounts_top_navigation.php'); ?></tD></TR>
  <tr>
    <td valign="top">
	<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="150" valign="top" align="left">
<div id="leftCol">
 		 <?php
 		 if(isset($_SESSION['id']) && $row['disp_profile'] != 'No')
 		 {
 		 	include("../../accounts/accounts_left_navigation.php");
 		 }
		 ?>
	</div>	<!-- Left Column -->
	</td>
    <td width="850" valign="top">
	  <?php
	  if(!isset($_SESSION['id']))
	  {
	  	header('Location: http://www.realivent.com/new_login.php');
	  }
	  require('../config.php');
	  $listing_id = $_GET['listing_id'];
	  /*	require_once 'SOAP/Client.php';
	  $wsdl = new SOAP_WSDL('http://realivent.com/soap/soap.php?wsdl');
	  $googleProxy = $wsdl->getProxy();
	  $out = $googleProxy->get_Listing_Details($listing_id);*/
	  $_SESSION['out'] = $out;
	  $user = $_SESSION['id'];
	  //echo $user->ID;
?>
      <link href="../style.css" rel="stylesheet" type="text/css" />
      <style type="text/css">
<!--
.style3 {color: #cc0000}
.style4 {font-size: 18px}
-->
      </style>
      <script language="javascript">
      function submit_form(listing_id, path, id, loc, user_id, membership)
      {
      	//alert(listing_id+" path="+path+" id="+id+" loc="+loc)
      	var theform = "form"+id
      	<?php
      	if(true)
      	{
      		?>
      		var theitem = document.getElementById('group'+id).selectedIndex
      		var itemvalue = document.getElementById('group'+id).options[theitem].value
      		<?
      	}
      	else
      	{
      		?>
      		var itemvalue = 0
      		<?
      	}
      	?>
      	if(loc == 'preview')
      	{
      		window.location = 'preview.php?listing_id='+listing_id+'&template='+path+'&group='+itemvalue+'&user_id='+user_id
      	}
      	else if(loc == 'edit')
      	{
      		window.location = 'edit_templates.php?listing_id='+listing_id+'&template='+path+'&group='+itemvalue+'&user_id='+user_id
      	}
      	else if(loc == 'code')
      	{
      		window.location = 'get_code.php?listing_id='+listing_id+'&template='+path+'&group='+itemvalue+'&user_id='+user_id
      	}
      	else if(loc == 'email')
      	{
      		window.location = 'email_myself.php?listing_id='+listing_id+'&template='+path+'&group='+itemvalue+'&user_id='+user_id
      	}
      }
      </script>
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td valign="top" align="left">
                <?php include('../../accounts/change_listing_include.php'); ?>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-family:Arial, Helvetica, sans-serif">
                    <?php
                    $query = "select * from post_templates where (Access='public' or (Access='private' and owner = '".$_SESSION['id']."')) order by Name";
                    $result = mysql_query($query) or die ("SQL Error".mysql_error());
                    while($row=mysql_fetch_assoc($result))
                    {
					?>
                    <tr>
                      <td width="100" align="center" valign="top" style="border-bottom:1px dashed black;"><img style="padding:4px;" align="left" src=../templates/<?php echo $row['path']."/t_".$row['thumb']; ?>></td>
				  <td width="*" valign="top" style="border-bottom:1px dashed black;"><div align=left style="font-family:Arial, Helvetica, sans-serif"><strong><?php echo $row['name']; ?></strong></div>
				  <div align="left" style="font-size:12px;">
				    <a href=# onClick="submit_form('<?php echo $listing_id ?>', '<?php echo $row['id'];?>', '<?php echo $row['id']; ?>', 'preview', '<?php echo $_SESSION['id']?>')">Preview</a> |
				    <a href=# onClick="submit_form('<?php echo $listing_id ?>', '<?php echo $row['id'];?>', '<?php echo $row['id']; ?>', 'edit', '<?php echo $_SESSION['id']?>')">Edit Template</a> |
				    <a href=# onClick="submit_form('<?php echo $listing_id ?>', '<?php echo $row['id'];?>', '<?php echo $row['id']; ?>', 'code', '<?php echo $_SESSION['id']?>')">Get Code</a> |
				    <a href=# onClick="submit_form('<?php echo $listing_id ?>', '<?php echo $row['id'];?>', '<?php echo $row['id']; ?>', 'email', '<?php echo $_SESSION['id']?>')">Email To Myself</a> |
				    <a href="download_pdf.php?listing_id=<?php echo $listing_id ?>&template=<?php echo $row['id']?>" target="_blank">Download Print Flyer</a></div>
				  <div style="padding-top:10px;" align="left">
				    <form action="preview.php?listing_id=<?php echo $listing_id ?>&template=<?php echo $row['path'];?>&user_id=<?php echo $_SESSION['id'] ?>" method="post" id="form<?php echo $row['id']; ?>">
				      Add Document Group:<select id="group<?php echo $row['id']; ?>">
				        <option value=0>Do not use</option>
				        <?php
				        $db=mysql_connect("localhost","realinfo_crm","developer55gogo") or die(mysql_error());
				        mysql_select_db('realinfo_crm',$db) or die(mysql_error());
				        $pquery = "select * from document_grps where group_owner = '".$user."'";
				        $presult = mysql_query($pquery) or die ("SQL Error".mysql_error());
				        while($prop_row=mysql_fetch_assoc($presult))
				        {
						?>
				        <option value=<?php echo $prop_row['group_id']; ?>><?php echo $prop_row['group_name']; ?></option>
				        <?
				        }
						?>
				        </select> <a style="font-size:10px;" href=http://realivent.com/poster/account/documentmain.php?module=add_group>New Group</a>
				      </form>
				  </div>				</td>
			    </tr>
                    <?php
                    }
			?>
                    </table>			</td>
			  </tr>
			  <tr><td>
				<a href=http://realivent.com/poster/account/saved_templates.php>View Saved Templates</a> | <a style="font-size:12px;" href=list_templates.php>Edit your templates</a><BR><BR>
				</td></tr>
              </table>	  </td>
    </tr>
        <tr>
          <td></td>
    </tr>
      </table>
      </Div>
	</td>
  </tr>
</table>
	</td>
  </tr>
</table>
<?php include('../../footer.php'); ?>
</center>
</body>
</html>
<?php require("../../db/closedb.php");?>